<template>
  <div>
    <tableComponents :pagination="{currentPage,pageSize,total:list.all_num}" @handleCurrentChange="handleCurrentChange" @handleSizeChange="handleSizeChange" @sendUserSearch="getSearch" :searchData="userSearchData" :isHaveExport="false" :isHaveAdd="false">
      <template v-slot:table>
        <el-table ref="multipleTable" :data="list.data" v-loading="loading" stripe header-row-class-name="head_color" tooltip-effect="dark" style="width: 99.8%">
          <el-table-column label="头像" min-width="80">
            <template slot-scope="scope">
              <div class="img_bor_tx">
                <img :src="$fnc.getImgUrl(scope.row.avatar)" alt />
              </div>
            </template>
          </el-table-column>

          <el-table-column label="用户信息" min-width="190">
            <template slot-scope="scope">
              <div class="tab_div">
                <div>
                  <span>用户昵称：</span>
                  <span>{{scope.row.nickname || '----'}}</span>
                </div>
                <div>
                  <span>会员账号：</span>
                  <span>{{scope.row.username}}</span>
                </div>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="订单" min-width="190">
            <template slot-scope="scope">
              <div class="tab_div">
                <div>
                  <span>交易类型：</span>
                  <span>{{ scope.row.types==1?'买入':'卖出'}}</span>
                </div>
                <div>
                  <span>订单号：</span>
                  <span>{{scope.row.oid}}</span>
                </div>
                <div>
                  <span>产品名称：</span>
                  <span>{{scope.row.title}}</span>
                </div>
                <div>
                  <span>提交时间：</span>
                  <span>{{ scope.row.update_time | getTimeFormat }}</span>
                </div>
                <div>
                  <span>更新时间：</span>
                  <span>{{ scope.row.update_time | getTimeFormat }}</span>
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="picture" header-align="center" align="center" min-width="160" label="图片">
            <template slot-scope="scope">
              <el-popover placement="right" title trigger="hover">
                <img :src="scope.row.piclink" style="width: 500px" />
                <img slot="reference" :src="scope.row.piclink" :alt="scope.row.piclink" style="width: 100px" />
              </el-popover>
            </template>
          </el-table-column>
          <el-table-column label="数量/价格" min-width="190">
            <template slot-scope="scope">
              <div class="tab_div">
                <!-- <div>
                  <span>币种：</span>
                  <span>{{ scope.row.iden}}</span>
                </div> -->
                <div>
                  <span>数量：</span>
                  <span>{{Number(scope.row.number)}}</span>
                </div>
                <div>
                  <span>价格：</span>
                  <span>{{Number(scope.row.price)}}</span>
                </div>

              </div>
            </template>
          </el-table-column>

          <el-table-column label="数量/价格" min-width="190">
            <template slot-scope="scope">
              <div class="tab_div">

                <div>
                  <span>剩余数量：</span>
                  <span>{{Number( scope.row.sy_number)}}</span>
                </div>
                <div>
                  <span>完成数量：</span>
                  <span>{{ Number(scope.row.wc_number)}}</span>
                </div>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="状态" min-width="180">
            <template slot-scope="scope">
              <div class="tab_div">
                <div>
                  <span>状态：</span>
                  <span class="rat" :class="[scope.row.status=='0' ? 'lei_red' : '']">{{ scope.row.status=='0'?"未完成":'已完成'}}</span>
                </div>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="操作" align="left" min-width="100">
            <template slot-scope="scope">
              <el-button :loading="$store.state.isLoading" class="mar_bottom_15" size="mini" type="primary" @click="toRecord(scope.row)">查看</el-button>
              <br />
            </template>
          </el-table-column>
        </el-table>
      </template>
    </tableComponents>
  </div>
</template>
<script>
import { transactionSearchData } from "@/assets/js/searchData/searchData"; //引入搜索的数据
export default {
  data() {
    return {
      userSearchData: transactionSearchData,
      show: false,
      myshow: false,
      loading: false,
      list: [],
      allPage: 0,
      allNum: 0,
      pageSize: 10,
      currentPage: 1,
      editId: "",
      multipleSelection: "",
      arr: [],
      visible: false,
      clickNum: 1,
      updataIndex: "",
      searchAll: {},
      dioForm: false,
      form: {
        id: "",
        point: "",
        rf: "",
      },
      end: false,
    };
  },

  methods: {
    getBz() {
      this.$api.getCoin.getBz({}).then((res) => {
        if (res.data.code == 200) {
          this.bzList = res.data.result;
          this.$store.commit("setBzList", res.data.result);
        }
      });
    },
    toRecord(row) {
      if (row.types == 1) {
        console.log(1);
        this.$router.push({
          path: "/index/dz/transaction_order",
          query: { buy_oid: row.oid || "" },
        });
      } else {
        this.$router.push({
          path: "/index/dz/transaction_order",
          query: { sell_oid: row.oid || "" },
        });
      }
    },

    handleSwitch(val, id) {
      //审核
      var params = {};
      params["id"] = id;
      val == true ? (params["is_show"] = 1) : (params["is_show"] = 0);
      this.$api.getCoin.lockCoinMachine(params).then((res) => {
        //this.getNewsAll();
      });
    },

    showAddDialog() {
      this.show = true;
    },
    getSearch(obj) {
      this.searchAll = obj;
      this.$router.push(this.$route.path + "?page=" + 1);
      this.getNewsAll(obj);
    },
    getNewsAll(data) {
      this.loading = true;
      var params = {};
      data = data || {};
      params = data;
      this.$api.getOc.getTransaction(params).then((res) => {
        if (res.data.code == 200) {
          this.list = res.data.result;
        }
        this.loading = false;
      });
    },
    handleSizeChange(val) {
      var params = this.searchAll;
      params.page = "";
      params.page_size = val;
      this.getNewsAll(params);
      this.pageSize = val;
      // console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      this.$router.push(this.$route.path + "?page=" + val);
    },
    handleSelectionChange(val) {
      //多选框赋值
      this.multipleSelection = val;
    },
    delSelection() {
      //删除
      this.$swal({
        title: "您确定要删除所选信息吗",
        text: "删除后将无法恢复，请谨慎操作！",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "是的，我要删除",
        cancelButtonText: "容我三思",
      }).then((willDelete) => {
        if (willDelete.value) {
          var str = "";
          for (var i in this.multipleSelection) {
            str += this.multipleSelection[i].id + "@";
          }
          str = str.slice(0, -1);
          var data = { id_str: str };
          this.$api.getCoin.delcoinOrder(data).then((res) => {
            if (res.data.code == 200) {
              this.$swal("删除成功！", "您已经删除了所选信息。", "success");
              this.getNewsAll();
            } else {
              this.$swal("删除失败！", "出错啦！", "success");
            }
          });
        }
      });
    },
    deleteNew(index, id) {
      this.$swal({
        title: "您确定要删除这条信息吗",
        text: "删除后将无法恢复，请谨慎操作！",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "是的，我要删除",
        cancelButtonText: "容我三思",
      }).then((willDelete) => {
        if (willDelete.value) {
          var data = { id_str: id };
          this.$api.getCoin.delcoinWithdraw(data).then((res) => {
            if (res.data.code == 200) {
              this.$swal("删除成功！", "您已经删除了这条信息。", "success");
              this.getNewsAll();
            } else {
              this.$swal("删除失败！", "出错啦！", "success");
            }
          });
        }
      });
    },
    showEditDialog(id) {
      this.myshow = true;
      this.editId = id;
      this.clickNum++;
    },
    reload(id) {
      this.getNewsAll();
    },
  },

  created() {
    this.getNewsAll();
    this.getBz();
  },
  computed: {},
  watch: {
    $route() {
      var params = this.searchAll;
      params.page = this.$route.query.page || 1;
      params.page_size = this.pageSize;
      this.getNewsAll(params);
      this.currentPage = Number(this.$route.query.page) || 1;
    },
  },
};
</script>

<style lang="less" scoped>
thead > tr > th {
  height: 45px;
  line-height: 45px;
}
td,
th {
  border: 1px solid #e1e3e4;
  font-size: 12px;
}
th {
  background: #f8f8f8;
  font-weight: normal;
  color: #323437;
}
td {
  height: 75px;
  color: #000;
}
.caozuo {
  padding-left: 50px;
}
.pl {
  padding-left: 15px;
}
.chkBox {
  display: block;
  margin: 0 auto;
  width: 18px;
  height: 18px;
  background: #fff;
}
.aBtn_1 {
  padding: 10px;
}
</style>
